/**
 * 
 */
package me.myachievements.persistence.account;

import java.util.Date;

import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;

import me.myachievements.persistence.PersistenceManagerImpl;

/**
 * @author besseym
 *
 */
public class AccountPersistenceManagerImpl extends PersistenceManagerImpl<Account> implements AccountPersistenceManager {

	/**
	 * Constructor
	 */
	public AccountPersistenceManagerImpl(){
		super(Account.class);
	}
	
	/*
	 * (non-Javadoc)
	 * @see me.myachievements.persistence.PersistenceManagerImpl#update(me.myachievements.persistence.PersistentObject)
	 */
	@Override
	public void update(Account account){
		account.setUpdatedOn(new Date());
		super.update(account);
	}
	
	/*
	 * (non-Javadoc)
	 * @see me.myachievements.persistence.account.AccountPersistenceManager#get(java.lang.String)
	 */
	public Account get(String username){
		return (Account) this.getCurrentSession()
			.createCriteria(Account.class)
			.add(Restrictions.eq("username", username))
			.setFetchMode("goals", FetchMode.JOIN)
			.setFetchMode("goals.tags", FetchMode.JOIN)
			.uniqueResult();
	}

}
